package myProject.gwt.client.dynamicTable;

import com.google.gwt.event.dom.client.HasScrollHandlers;
import com.google.gwt.event.dom.client.ScrollHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.SimplePanel;

public class ScrollBar extends Composite implements HasScrollHandlers{

	private ScrollPanel sp = new ScrollPanel();
	private SimplePanel dummyPanel = new SimplePanel();
	private boolean isHorizontal;
	
	public ScrollBar(boolean isHorizontal){
		this.isHorizontal = isHorizontal;
		initWidget(sp);
		if(isHorizontal){
			sp.setHeight("20px");
			dummyPanel.setHeight("50px");
		}else{
			sp.setWidth("20px");
			dummyPanel.setWidth("50px");
		}
		sp.setWidget(dummyPanel);		
		setScrollMax(10000);
	}
	
	public void setScrollMax(int max){
		if(isHorizontal){
			dummyPanel.setWidth(max+"px");
		}else{
			dummyPanel.setHeight(max+"px");
		}
	}
		
	public int getScrollPosition(){
		if(isHorizontal){
			return  sp.getHorizontalScrollPosition();
		}
		else{
			return sp.getScrollPosition();
		}
	}

	@Override
	public HandlerRegistration addScrollHandler(ScrollHandler handler) {
		return sp.addScrollHandler(handler);
	}
}
